Skip to content

Fix memory leaks in search query and response lifecycle#33

Merged
marcosgz merged 6 commits intomainfrom
marcosgz/mem-leak
Mar 18, 2026
Merged

Fix memory leaks in search query and response lifecycle#33
marcosgz merged 6 commits intomainfrom
marcosgz/mem-leak

Conversation

@marcosgz
Copy link
Copy Markdown
Owner

@marcosgz marcosgz commented Feb 26, 2026

Summary

  • Scroll context leak fix: Extract scroll_id from the initial response before entering the loop in scroll_hits, ensuring ES scroll contexts are always cleared even if the yield block raises on the first iteration
  • Break Response → Query circular reference: Response now stores query_definition (a Hash) instead of the full Query object, allowing the GC to collect responses and their associated raw response hashes independently
  • Make Query#reset! public: Apps can now explicitly clear cached @response on reused Query objects to release memory
  • Lightweight event payloads: Event instrumentation now stores query_definition instead of the full Query object reference, preventing accidental retention via subscriber payloads

- Extract scroll_id before the loop in scroll_hits to ensure ES scroll
  contexts are always cleared, even if yield raises on the first iteration
- Break Response → Query circular reference by storing query_definition
  instead of the full Query object, allowing GC to collect responses
- Make Query#reset! public so apps can clear cached responses
- Use lightweight query_definition in event payloads instead of retaining
  the full Query object reference
@marcosgz marcosgz merged commit 5d44262 into main Mar 18, 2026
41 of 42 checks passed
@marcosgz marcosgz deleted the marcosgz/mem-leak branch March 18, 2026 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant